﻿@using LanDBom.Resources
@using LanDBom.Models
@{
    ViewBag.Title = "View";
    Layout = "~/Views/Shared/_Genertals.cshtml";
}
@section styles{
    <style>
        .YCFile {
            display: none;
            background-color: #fff;
            width: 350px;
            height: 150px;
            position: absolute;
            left: 22%;
            top: 40%;
        }

        .YANds {
            display: flex;
            align-items: center;
            justify-content: space-between;
            background-color: #0866a563;
            border-radius: 8px;
            margin: 3px 4px;
            padding: 2px 10px;
        }

        .SHnacs {
            display: flex;
            width: 96%;
            height: 65%;
            align-items: flex-start;
            justify-content: space-between;
            background-color: #cecece;
            border-radius: 8px;
            margin: 3px 4px;
            padding: 2px 10px;
        }
    </style>
}
<div>
    <div title="@Resource.String155">
        @using (Html.BeginForm("Cliview", "Application", FormMethod.Post))
        {
            <fieldset class="boun">
                <legend class="len1 ">物料信息</legend>
                <div class="row">
                    <p class="col-3">@Html.Label(Resource.String210)  @Html.TextBox("KHname")</p>
                    <p class="col-3">@Html.Label(Resource.String211):@Html.TextBox("KHPhone")</p>
                    <p class="col-3"><input type="submit" id="BomS" value="@Resource.String155" class="btn-secondary btn-sm" /></p>
                </div>
            </fieldset>
        }
        @Html.ActionLink("添加客户信息", "Custom", new { Controller = "Custom", Action = "Custom" }, new { @class = "btn", @style = "margin-top:10px;" })
        <input type="button" id="btn_chuan" value="@Resource.String92" class="btn" />
    </div>
    <div title="查询列表" style="height:70vh;overflow-x:scroll;overflow-y:hidden">
        <table class="table tab">
            <thead class="thead-light">
                <tr class="kuna" style="text-align:center">
                    <th scope="col" style="width:50px;">@Resource.String213</th>
                    <th scope="col" style="width:100px;">@Resource.String214</th>
                    <th scope="col" style="width:300px;">@Resource.String215</th>
                    <th scope="col">@Resource.String216</th>
                    <th scope="col">@Resource.String217</th>
                    <th scope="col">@Resource.String218</th>
                    <th scope="col">@Resource.String219</th>
                    <th scope="col">@Resource.String220</th>
                    <th scope="col">货币</th>
                    <th scope="col">所属人</th>
                    <th scope="col">助记码</th>
                    @if (MyAuthentication.IsLogin())
                    {
                        if (MyAuthentication.GetUsers().DE_quan == "管理员")
                        {
                            <th scope="col" style="width:200px;">@Resource.String221</th>
                        }
                    }

                </tr>
            </thead>
            <tbody class="JINNlm" style="height:550px; overflow-y:hidden">
                @foreach (Clirntele item in Model)
                {
                    <tr>
                        <td style="width:50px;">@item.CL_ID</td>
                        <td style="width:100px;">@item.CL_bian</td>
                        <td style="width:300px;">@item.CL_name</td>
                        <td>@item.CL_di</td>
                        <td>@item.CL_lian</td>
                        <td>@item.CL_you</td>
                        <td>@item.CL_bei</td>
                        <td>@item.CL_ju</td>
                        <td>@item.CL_Huobi</td>
                        <td>@item.CL_shuo</td>
                        <td>@item.CL_zhu</td>
                        @if (MyAuthentication.IsLogin())
                        {
                            if (MyAuthentication.GetUsers().DE_quan == "管理员")
                            {
                                <td style="width:200px;"><span id="Xiu_cli" class="DEL_c DEL_c_Y">@Resource.String222</span>|<span id="Del_Cli" class="DEL_c DEL_c_D">@Resource.String223</span>|<span  id="TOngbu_ss" class="DEL_c DEL_c_H">同步至ERP</span></td>
                            }
                        }
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div style="display: flex; justify-content: space-between;">
        <span>共 @ViewBag.Yeshu 行</span>
        @using (Html.BeginForm("Cliview", "Application", FormMethod.Post))
        {<nav aria-label="Page navigation example" class="row" style="margin-right:50px;">
                <ul class="pagination">
                </ul>
                共<span id="komdr">@ViewBag.Shund</span>页
            </nav>
        }
    </div>
    @*批量添加模块*@
    <div id="tinajia" class="YCFile">
        <div class="YANds"><span>@Resource.String108</span><span><i class="bi bi-x-circle-fill" id="Quxiao"></i></span></div>
        <div class="SHnacs">
            <input type="file" value="" id="SHanngcF" accept="" />
            <input type="button" value="@Resource.String108" id="TIjaio" />
        </div>
    </div>
</div>
@section scripts{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li17").css({ "color": "black", "background-color": "white" })
            $(document).on("click", "#Del_Cli", function () {
                if (confirm("是否删除该行！")) {
                    var CL_id = $(this).parent().parent().children().first().text()//CL_ID
                    $.ajax({
                        url: "/Application/Cliview",
                        type: "POST",
                        data: { "Bian": CL_id, "stents": 1 },
                        success: function (path) {
                            location.reload(true);
                            alert(path)
                        },
                        error: function () {
                            alert("系统错误!");
                        }
                    })
                }
            })
            $(document).on("click", "#btn_chuan", function (e) {
                $("#tinajia").css({ "display": "block" })
            })
            //关闭文件上传
            $(document).on("click", "#Quxiao", function () {
                $("#tinajia").css({ "display": "none" })
            })
            //提交文件
            $("#TIjaio").click(function () {
                var fileUpload = $('#SHanngcF')[0];
                if (fileUpload.files.length > 0) {
                    var formData = new FormData();
                    formData.append('file', fileUpload.files[0]);
                    console.log(formData)
                    $.ajax({
                        url: '/Application/Kehupl',
                        type: 'POST',
                        data: formData,
                        processData: false,		//用于对data参数进行序列化处理 这里必须false
                        contentType: false,
                        success: function (fgggh) {
                            if (fgggh.length == 0) {
                                alert("该文件已打开，请关闭后重试！")
                            } else {
                                alert(fgggh)
                                $("#tinajia").hide()
                            }
                        },
                        error: function (xhr) {
                            alert("系统错误" + xhr);
                        }
                    })
                } else {
                    alert('请选择要上传的文件！');
                }
            })
            //分页
            $(document).ready(function () {
                var sjnd="1"
                fenye(sjnd)
            })
            function fenye(a) {
                var hjin=a*1
                var shunddd = $("#komdr").text() * 1
                $(".pagination li").remove()
                var $ul = ""
                $ul += (`<li class="page-item"><span class="page-link shiyong"><<<</span></li>`)
                for (var i = 1; i <= shunddd; i++) {
                    if (a<4) {
                        if (i < 5) {
                            if (hjin == i) {
                                $ul += "<li class='page-item'><span class='page-link shiyong' id='shiyongll' style='background-color:#c4ded9'>" + i + "</span></li>";
                            } else {
                                $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                            }
                        } else {
                            $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                            break
                        }
                    }
                    if (a >= 4) {
                        if (i < (hjin - 2)) {
                            continue
                        }
                        if (i > (hjin - 2) && i < (hjin + 2)) {
                            if (hjin == i) {
                                $ul += "<li class='page-item'><span class='page-link shiyong' id='shiyongll' style='background-color:#c4ded9'>" + i + "</span></li>";
                            } else {
                                $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                            }
                        } else {
                            $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                        }
                        if (i >= (hjin + 2)) {
                            break
                        }
                    }
                    
                }
                $ul += (`<li class="page-item"><span class="page-link shiyong">>>></span></li>`);
                $(".pagination").append($ul)
            }
            $(document).on("click", ".shiyong", function () {
                var shunddd = $("#komdr").text()
                var sjind = $(this).text()
                sjind = sjind == "<<<" ? "1" : sjind == ">>>" ? shunddd*1 : sjind*1
                fenye(sjind)
                $.ajax({
                    url: '/Application/Cliview',
                    type: 'POST',
                    data: { "shund": sjind - 1, "stents": 2, "KHname": $("#KHname").val(), "KHPhone": $("#KHPhone").val() },
                    success: function (fgggh) {
                        gujd(fgggh)
                    },
                    error: function (xhr) {
                        alert("系统错误" + xhr);
                    }
                })
            })
            function gujd(sj) {
                $(".JINNlm tr").remove()
                $.each(sj, function (i,item) {
                    var $tr = $(`<tr>
                        <td style="width:50px;">${item.CL_ID}</td>
                        <td style="width:100px;">${item.CL_bian}</td>
                        <td style="width:300px;">${item.CL_name}</td>
                        <td>${item.CL_di}</td>
                        <td>${item.CL_lian}</td>
                        <td>${item.CL_you}</td>
                        <td>${item.CL_bei}</td>
                        <td>${item.CL_ju}</td>
                        <td>${item.CL_Huobi}</td>
                        <td>${item.CL_shuo}</td>
                        <td>${item.CL_zhu}</td>
                        @if (MyAuthentication.IsLogin())
                        {
                            if (MyAuthentication.GetUsers().DE_quan == "管理员")
                            {
                                <td><span id="Xiu_cli" class="DEL_c DEL_c_Y">@Resource.String222</span>|<span id="Del_Cli" class="DEL_c DEL_c_D">@Resource.String223</span></td>
                            }
                        }

                    </tr>`)
                    $(".JINNlm").append($tr)
                })

            }
            $(document).on("click", "#Xiu_cli", function () {
                var Id = $(this).parent().parent().children().eq(0).text()
                window.location.href = "/Custom/ViewEdit?id=" + Id;
            })
            $(document).on("click", "#TOngbu_ss", function () {
                var id = $(this).parent().parent().children().eq(0).text()
                $.ajax({
                    url: '/Application/Tongbu',
                    type: 'POST',
                    data: { "id": id },
                    success: function (fgggh) {
                        alert(fgggh)
                    },
                    error: function (xhr) {
                        alert("系统错误" + xhr);
                    }
                })
            })
        })

    </script>

}
